package concurrent;

import java.util.ArrayList;
import java.util.List;

public class ThreadPool {
	private int maxPoolSize;
	List<Thread> threads;
	
	public ThreadPool(int maxPoolSize) {
		this.maxPoolSize = maxPoolSize;
		threads = new ArrayList<Thread>();
	}
	
	public void execute(Runnable task) {
		threads.size();
		if (threads.size() >= maxPoolSize) {
			return;
		}
		threads.add(null);
		System.out.println("1");
		System.out.println(threads.size());
		/*
		 * Thread t = new Thread(task); t.start(); threads.add(t);
		 */
	}
	
	public static void main(String[] args) {
		/*
		 * ThreadPool pool = new ThreadPool(10); pool.execute(new Runnable() {
		 * 
		 * @Override public void run() {
		 * System.out.println(Thread.currentThread().getName() + ": run方法执行"); } });
		 */
		System.out.println("hello");
		ThreadPool pool = new ThreadPool(5);
		for (int i = 0; i < 50; i++) {
			new Thread(new Runnable() {
				@Override
				public void run() {
					pool.execute(null);
				}
			}).start();
		}
	}
}
